//
//  GameStatusBar.m
//  Coffee
//
//  Created by sabhanayagam b on 4/29/11.
//  Copyright 2011 Cognizant. All rights reserved.
//

#import "MGameStatusBar.h"
#import "GameManager.h"
#import "MenuItems.h"
#import "MResumeGameLayer.h"
@implementation MGameStatusBar
// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init] )) {
		self.isTouchEnabled = YES; 
		[self addChild:[MenuItems buttonWithSelector:@selector(itemClickHandler:) target:self label:@"pause"] z:0 tag:STATUS_BAR];
	}
	return self;
}
-(void) itemClickHandler: (id) sender
{
	[[GameManager sharedGameInfo]pauseGame];
	[(CCMultiplexLayer*)parent_ switchTo:1];
	
}

-(void) registerWithTouchDispatcher
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
}

// Implements logic to check if the touch location was in an area that this layer wants to handle as input.
-(bool) isTouchForMe:(CGPoint)touchLocation
{
	CCNode* node = [self getChildByTag:STATUS_BAR];
	return CGRectContainsPoint([node boundingBox], touchLocation);
}

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event
{
	CGPoint location = [GameManager locationFromTouch:touch];
	bool isTouchHandled = [self isTouchForMe:location];
	// Always swallow touches, GameLayer is the last layer to receive touches.
	return isTouchHandled;
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}
@end
